﻿package tbo.world 
{
	import tbo.actors.Actor;
	
	/**
	 * ...
	 * @author ...
	 */
	public class TacticalGrid 
	{
		protected var _grid:Array;
		
		public function TacticalGrid(wid:Number = 1, hig:Number = 1) 
		{
			_grid = new Array(hig);
			for (var i:Number = 0; i < _grid.length; i++) {
				_grid[i] = new Array(wid);
				
				for (var y:Number = 0; y < _grid[i].length; y++) {
					var grdObj:Object = new Object();
					grdObj.walkable = 1;//Math.round(Math.random());
					_grid[i][y] = grdObj;
				}
			}
		}
		
		public function isWalkable(wx:Number, wy:Number):Boolean {

			if (_grid[wx] != null) {
				if(_grid[wx][wy] != null) {
					return _grid[wx][wy].walkable;
				}
			}
			
			return false;
		}
		
		public function get length():Number {
			return _grid[0].length;
		}
		
		public function get height():Number {
			return _grid.length;
		}
		
		public function setUnit(u:Actor):void {
			_grid[u._wx][u._wy].unit = u;
		}
		
		public function getGridData(x:Number, y:Number):* {
			if(_grid[x][y] != null)
				return(_grid[x][y]);
			else
				return null;
		}
		
	}
	
}